package dmsxl.lianbiao;

/**
 * Author: Zhang Dongwei
 * Date: 2023/8/10 14:21
 */
public class unionone {
    static class ListNode1{
        int val;
        ListNode1 next;
        ListNode1(){}
        ListNode1(int val){
            this.val = val;
        }
        ListNode1(int val, ListNode1 next){
            this.val = val;
            this.next = next;
        }
    }

    public static void main(String[] args) {
        ListNode1 node = new ListNode1(1);
        ListNode1 node1 = new ListNode1(2);
        ListNode1 node2 = new ListNode1(3);
        ListNode1 node3 = new ListNode1(4);
        ListNode1 node4 = new ListNode1(5);
        node.next = node1;
        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        ListNode1 res = reverseList1(node);
        while (res != null){
            System.out.println(res.val);
            res = res.next;
        }
    }

    public static ListNode1 reverseList1(ListNode1 head) {
        ListNode1 cur = head;
        ListNode1 pre = null;
        while (cur != null){
            ListNode1 temp = cur.next;
            cur.next = pre;
            pre = cur;
            cur = temp;
        }
        return pre;
    }
}
